package com.chenfan.process.event.callback;

import com.chenfan.notify.dto.NotifyDTO;
import com.chenfan.process.biz.impl.NotifyBiz;
import lombok.SneakyThrows;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.context.event.EventListener;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Component;
import org.springframework.util.CollectionUtils;

import java.util.List;

/**
 * @author K
 * @date 2021/1/27
 */
@RefreshScope
@Component
public class NotifyListener {

    @Autowired
    private NotifyBiz notifyBiz;

    @SneakyThrows
    @Async("threadPoolTaskExecutor")
    @EventListener({NotifyEvent.class})
    public void onApplicationEvent(NotifyEvent event) {
        List<NotifyDTO> triggerCallbackEventDataList = event.getNotifyList();
        if (CollectionUtils.isEmpty(triggerCallbackEventDataList)) {
            return;
        }
        notifyBiz.sendNotify(triggerCallbackEventDataList);
    }
}
